import Vue from 'vue'
import Router from 'vue-router'
import report from './menus/report'
import InfoManage from './menus/infoManage'
import inspection from './menus/inspection'
import hr from './menus/hr'

Vue.use(Router)

const router = new Router({
    mode: 'hash',
    base: process.env.BASE_URL,
    routes: [
        {
            path: '/',
            component: () => import('@/views/login/Index.vue')
        },
        {
            path: '/home',
            redirect: '/login',
            component: () => import('@/views/Index.vue'),
            children: [
                {
                    path: '/home',
                    name: 'menuIndex',
                    meta: {
                        title: '首页',
                        icon: 'el-icon-house'
                    },
                    component: () => import('@/views/BI/front.vue')
                },
                {
                    path: '/notice',
                    name: 'menuA1NoticeOrder',
                    meta: {
                        title: '销售产品通知',
                        icon: 'el-icon-notebook-2'
                    },
                    component: () => import('@/views/notice/notice_index.vue')
                },
                {
                    path: '/product/design',
                    name: 'menuA1ProductDesign',
                    meta: {
                        title: '加工产品通知',
                        icon: 'el-icon-notebook-2'
                    },
                    component: () => import('@/views/process-route/product_design.vue')
                },
                {
                    path: '/process/version-management',
                    name: 'menuA1ProcessRouteLibrary',
                    meta: {
                        title: '产品工艺库',
                        icon: 'el-icon-notebook-2'
                    },
                    component: () => import('@/views/process-route/version_management.vue')
                },
                // {
                //   path: '/process/design',
                //   name: 'menuA1ProcessDesign',
                //   meta: {
                //     title: '产品工艺设计',
                //     icon: 'el-icon-notebook-2',
                //   },
                //   component: () => import('@/views/process-route/process_design.vue')
                // },
                {
                    path: '/process/route/approve',
                    name: 'menuA1ProcessRouteApprove',
                    meta: {
                        title: '产品工艺审批',
                        icon: 'el-icon-notebook-2'
                    },
                    component: () => import('@/views/process-route/process_approve.vue')
                },
                {
                    path: '/production/dispatch',
                    name: 'menuA1DispatchNotice',
                    meta: {
                        title: '生产通知派工',
                        icon: 'el-icon-s-order'
                    },
                    component: () => import('@/views/production-dispatch/notice_cards.vue')
                },
                {
                    path: '/dispatch/form',
                    name: 'menuA1DispatchForm',
                    meta: {
                        title: '路线单列表',
                        icon: 'el-icon-s-order'
                    },
                    component: () => import('@/views/production-dispatch/dispatch_forms.vue')
                },
                // notice,
                // processRoute,
                // dispatch,
                inspection,
                hr,
                // {
                //     path: '/inspection',
                //     name: 'menuA1Inspection',
                //     meta: {
                //         title: '质量流程管理',
                //         icon: 'el-icon-brush'
                //     },
                //     component: () => import('@/views/inspection/Index.vue')
                // },
                {
                    path: '/attendance',
                    name: 'menuA1Attendance',
                    meta: {
                        title: '单项任务审批',
                        icon: 'el-icon-s-custom'
                    },
                    component: () => import('@/views/attendance/Index.vue')
                },
                InfoManage,
                report,
                {
                    path: '/fapiao/list',
                    name: 'fapiao-list',
                    meta: {
                        title: '发票申请',
                        icon: 'el-icon-house'
                    },
                    component: () => import('@/views/fapiao/fapiao-list.vue')
                },
                {
                    path: '/goto/v2',
                    name: 'goto-v2',
                    meta: {
                        title: '跳转物料系统',
                        icon: 'el-icon-house'
                    },
                    component: () => import('@/views/goto/v2.vue')
                },

               
                // 从这里往下的路由均是非导航栏路由
                {
                    path: '/fapiao/detail',
                    name: 'fapiao-detail',
                    meta: {
                        title: '发票详情',
                        icon: 'el-icon-house'
                    },
                    component: () => import('@/views/fapiao/fapiao-detail.vue')
                },
                {
                    path: '/notice/detail',
                    name: 'detail',
                    component: () => import('@/views/notice/detail.vue')
                },
                {
                    path: '/process/design',
                    name: 'design',
                    component: () => import('@/views/process-route/design_process.vue')
                },
                {
                    path: '/process/add-process-detail',
                    name: 'add-process-detail',
                    component: () => import('@/views/process-route/add_process_detail.vue')
                },
                {
                    path: '/process/process-route-design',
                    name: 'process-route-design',
                    component: () => import('@/views/process-route/process_route_design.vue')
                },
                {
                    path: '/process/review',
                    name: 'process-review',
                    component: () => import('@/views/process-route/process_review.vue')
                },
                {
                    path: '/dispatch/details',
                    name: 'dispatch-details',
                    component: () => import('@/views/production-dispatch/dispatch_details.vue')
                },
                {
                    path: '/au/role',
                    name: 'role-manager',
                    component: () => import('@/views/auManage/role-manage.vue')
                },
                {
                    path: '/au/authority',
                    name: 'authority-manager',
                    component: () => import('@/views/auManage/authority-manage.vue')
                },
                {
                    path: '/notice/product/list',
                    name: 'noticeProductList',
                    component: () => import('@/views/notice/product_list.vue')
                },
                {
                    path: '/empty',
                    name: 'emptyPage',
                    component: () => import('@/views/_common/empty_page.vue')
                }
            ]
        }
    ]
})

// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
    // to为将要访问的路径，from代表从哪个路径跳转而来，next是一个函数表示放行
    if (to.path === '/') return next()
    // 获取token
    const tokenStr = window.sessionStorage.getItem('token')
    // 没有token的访问将被强制跳转到'/'登录页面
    if (!tokenStr) return next('/')
    next()
})

export default router
